//
//  DHMainViewController.m
//  宏达APP
//
//  Created by 123 on 2018/4/26.
//  Copyright © 2018年 123. All rights reserved.
//

#import "DHMainViewController.h"
#import "DHBaseViewController.h"
#import "DHNavViewController.h"
#import "DHNetworkManager.h"
#import "DHNetworkManager+DHHodaNetworkManager.h"

@interface DHMainViewController ()

@property(nonatomic,strong)NSArray<NSDictionary *> *childVCInfo; ///子控制器信息数组字典

@end



@implementation DHMainViewController

- (NSArray *)childVCInfo{
    if (!_childVCInfo) {
        _childVCInfo = @[@{@"clsName":@"DHHomeController",@"name":@"首页",@"imgName":@"首页1",@"imgNameHL":@"首页"},
                         @{@"clsName":@"DHClassController",@"name":@"分类",@"imgName":@"分类1",@"imgNameHL":@"分类"},
                         @{@"clsName":@"DHExChangeController",@"name":@"攒机",@"imgName":@"工具1",@"imgNameHL":@"工具"},
                         @{@"clsName":@"DHShopCartController",@"name":@"购物车",@"imgName":@"购物车1",@"imgNameHL":@"购物车"},
                         @{@"clsName":@"DHProfileController",@"name":@"我的",@"imgName":@"我的1",@"imgNameHL":@"我的"}
                         ];
    }
    return _childVCInfo;
}

- (void)viewDidLoad {
    [super viewDidLoad];
//    [DHNetworkManager.shareManager loadGoodList];
        
    [self setUpChildViewController];
}

- (void)setUpChildViewController{
    
    NSMutableArray<UIViewController *> *arrayM = [NSMutableArray array];
    
    //循环创建子控制器
    for (NSDictionary *dictInfo in self.childVCInfo) {
        [arrayM addObject:[self createChildViewControllerWithDict:dictInfo]];
    }
    //设置子控制器
    self.viewControllers = arrayM;
}

#pragma mark: - 创建子控制器
#define tabbarFontSize 14
- (UIViewController *)createChildViewControllerWithDict:(NSDictionary *)dict{
    //获取子控制器信息
    NSString *clsName = dict[@"clsName"];
    NSString *name = dict[@"name"];
    NSString *imgName = dict[@"imgName"];
    NSString *imgNameHL = dict[@"imgNameHL"];
    UIImage *img = [UIImage imageNamed:imgName];
    UIImage *imgHL = [UIImage imageNamed:imgNameHL];
    
    
    //创建控制器
    UIViewController *vc = [[NSClassFromString(clsName) alloc] init];
    DHNavViewController *nav = [[DHNavViewController alloc] initWithRootViewController:vc];
    
    //设置tabbar
    vc.tabBarItem.image = [img resizableImageWithCapInsets:UIEdgeInsetsMake(3, 3, 3, 3) resizingMode:UIImageResizingModeStretch];//[img stretchableImageWithLeftCapWidth:vc.tabBarItem.largeContentSizeImage.size.width * 0.5 topCapHeight:vc.tabBarItem.largeContentSizeImage.size.height * 0.5];
    
    vc.tabBarItem.selectedImage = [imgHL stretchableImageWithLeftCapWidth:vc.tabBarItem.largeContentSizeImage.size.width * 0.5 topCapHeight:vc.tabBarItem.largeContentSizeImage.size.height * 0.5];
    
    vc.title = name;
    [vc.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:tabbarFontSize]} forState:0];
    [vc.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:tabbarFontSize]} forState:UIControlStateSelected];
    
    return nav;
    
}
@end
